﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Arbalest.Web.Services;
using Arbalest.Models;
using Arbalest.Web.Helpers;

namespace Arbalest.Web.Controllers
{
    public class StorageLocationTypeController : Controller
    {
        //
        // GET: /StorageLocationType/

        public ActionResult Index()
        {
            DataStore ds = new DataStore();
            return View(ds.GetList<StorageLocationType>());
        }

        //
        // GET: /Company/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Company/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Company/Create

        [HttpPost]
        public ActionResult Create(StorageLocationType company, FormCollection collection)
        {
            try
            {
                DataStore ds = new DataStore();
                ds.Add<StorageLocationType>(company);

                TempData[DataHelper.TempData.Alert] = new Alert
                {
                    Context = Alert.AlertContext.Success,
                    Markup = "Record added."
                };

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Company/Edit/5

        public ActionResult Edit(int id)
        {
            DataStore ds = new DataStore();

            return View(ds.GetList<StorageLocationType>().Where(rec => rec.Id == id).FirstOrDefault());
        }

        //
        // POST: /Company/Edit/5

        [HttpPost]
        public ActionResult Edit(StorageLocationType company, FormCollection collection)
        {
            try
            {
                DataStore ds = new DataStore();
                ds.Update<StorageLocationType>(company);

                TempData[DataHelper.TempData.Alert] = new Alert
                {
                    Context = Alert.AlertContext.Success,
                    Markup = "Record updated."
                };

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Company/Delete/5

        public ActionResult Delete(int id)
        {
            DataStore ds = new DataStore();

            return View(ds.GetList<StorageLocationType>().Where(rec => rec.Id == id).FirstOrDefault());
        }

        //
        // POST: /Company/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                DataStore ds = new DataStore();

                StorageLocationType storageLocationType = ds.GetList<StorageLocationType>().Where(rec => rec.Id == id).FirstOrDefault();
                ds.Remove<StorageLocationType>(storageLocationType);

                TempData[DataHelper.TempData.Alert] = new Alert
                {
                    Context = Alert.AlertContext.Success,
                    Markup = "Record removed."
                };

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
